package com.hooper.hospital.common.exception;

import com.hooper.hospital.common.result.Result;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * global exceptions handle
 *
 * @author Mind
 */
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    public Result error(Exception e) {
        e.printStackTrace();
        return Result.fail(e.getMessage());
    }

    @ExceptionHandler(HospitalException.class)
    public Result error(HospitalException e) {
        Result<Object> result = new Result<>();
        result.setMessage(e.getMessage());
        result.setCode(e.getCode());
        e.printStackTrace();
        return result;
    }
}
